package com.naiterui.ehp.bp.support.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

/**
 * <pre>
 *       由于项目中有的地方会使用HttpServletResponse 获取PrintWriter，然后直接输出数据到页面，所以需要统一设置UTF-8
 * </pre>
 *
 * @author 王泽浩
 * @date 2018/5/29 上午11:30
 * @since 1.0.0
 */
@Component
@DependsOn({"taskExecutor", "scheduledExecutorService", "springContextHolder"})
public class HttpServletResponseUtf8Filter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException,
            IOException {
        response.setCharacterEncoding("UTF-8");
        filterChain.doFilter(request, response);
    }
}
